package com.jake.mallseckill.multithreading;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class FixedThreadPoolDemo {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(4);
        final int threadCount = 100000;
        CountDownLatch countDownLatch = new CountDownLatch(threadCount);
        long from = System.currentTimeMillis();
        for (int i = 0; i < threadCount; i++) {
            String threadName = "t" + i;
            service.execute(new MyWorker(threadName, countDownLatch));
        }
        countDownLatch.await();
        long to = System.currentTimeMillis();
        long period = to - from;
        System.out.println("use " + period + " milliseconds");
        service.shutdown();
    }

}
